package com.lsj.spring.service.impl;

import com.lsj.spring.anno.Save;
import com.lsj.spring.dao.IUserDao;
import com.lsj.spring.mapper.UserMapper;
import com.lsj.spring.model.User;
import com.lsj.spring.service.IUserService;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.List;

/**
 * @author Lsj
 * @version 1.0
 * @date 2021/6/24 20:34
 * service注解会把这个类放在spring容器中
 */
@Service("userService")
@Scope(value = "singleton")
@AllArgsConstructor
public class UserServiceImpl implements IUserService {
    private final IUserDao userDao;
    private final UserMapper userMapper;
    @PostConstruct
    public void init(){
        System.out.println("初始化执行,bilibili");
    }
    @PreDestroy
    public void destory(){
        System.out.println("海贼王早死了");
    }

    /**
     * 查询
     *
     * @param id id
     * @return 用户
     */
    @Override
    public User select(int id) {
        List<User> list = userMapper.select();
        return userDao.selectById(id);
    }

    /**
     * 新加
     *
     * @param user 用户
     * @return int类型
     */
    @Override
    @Save(value = "测试姬",name = "用户阿萨姆")
    public int insert(User user) {
        System.out.println("新增用户为:");
        System.out.println(user);
        return 0;
    }
}
